; Colin's AutoHotkey configuration file

; Reminders:
;  ^ = control
;  ! = alt
;  # = windowskey
;  + = shift

; If this script is executed again, silently replace the previous instance
#SingleInstance force
; Set "#IfWinActive" et al to match anywhere in the WinTitle
SetTitleMatchMode 2 

; Set the current working directory to my home directory
SetWorkingDir, %HOME%

;
; Helper functions
;
CopySelectedTextToClipboard()
{
   ; Clear out the clipboard
   clipboard =
   ; Send typical copy hotkey
   Send ^c
   ; Wait for the clipboard to contain the link
   ClipWait
}

; Set path to different web browsers
FileGetShortcut, %HOME%\lnk\Internet Explorer.lnk, BrowserIe      
FileGetShortcut, %HOME%\lnk\Firefox.lnk,           BrowserFirefox 
FileGetShortcut, %HOME%\lnk\Chrome.lnk,            BrowserChrome  
FileGetShortcut, %HOME%\lnk\ChromeIncognito.lnk,   BrowserChromeIncognito
Browser        = %BrowserChrome%

; Remap Capslock to Control
; (But leave a way to turn Caps Lock on, via WindowsKey+Capslock)
#Capslock::Capslock
Capslock::Ctrl


;
; Hotstrings (replace text after the shortcut text + {space,',',CR})
; note: these appear to be case insensitive
;
::-th::Thanks,{Enter}Colin
::f.s.c::firmware.seagate.com

::-qe::Qentry: $

:?*:2day::
FormatTime, TimeString,, M/d/yyyy
SendInput %TimeString%
return

:?*:day2::
FormatTime, TimeString,, yyyyMMdd
SendInput %TimeString%
return

:?*:2morrow::
tmptime = ; empty variable since add will use current time
tmptime += 1, days
FormatTime, TimeString, %tmptime%, M/d/yyyy
SendInput %TimeString%
return


;
; Launch apps
;

; Common apps
^#w::Run, %Browser%
^+#w::Run, "%HOME%\lnk\ChromeIncognito.lnk"
^#f::Run, %BrowserFirefox%
^#z::Run, %BrowserIe%
^#c::Run, "%HOME%\lnk\Command Prompt.lnk", %HOME%
^#g::Run, gvim.exe
^#p::Run, "%HOME%\lnk\P4V.lnk"
;^#p::Run, "C:\Program Files\Perforce\p4v.exe"
^+#p::Run, "%HOME%\lnk\PuTTY.lnk"
^#i::Run, "%HOME%\lnk\iTunes.lnk"
^#k::Run, "%HOME%\lnk\KeePass.lnk"
^#r::Run, "%HOME%\lnk\RSA.lnk"

; Work apps
^#l::Run, "%HOME%\lnk\Labeler.lnk"

; Home apps & files
^#q::Run, "%HOME%\lnk\Quicken.lnk"
^+#q::Run, "%HOME%\lnk\FinancialControlJournal.lnk"
^!#p::Run, "%HOME%\lnk\Picasa.lnk"

; Web apps
^!#g::Run, "https://mail.google.com"


;
; Launch URLs with alternative browsers
;
; Note: my initial concept here was to grab highlighted text, but control-c
; does not copy the highlighted text in all contexts.  Thus, these assume
; that the link was already copied to the clipboard.
;
^!#f::
   ;CopySelectedTextToClipboard()
   Run, %BrowserFirefox% %clipboard%
return

^!#z::
   ;CopySelectedTextToClipboard()
   Run, %BrowserIe% %clipboard%
return

^!#w::
   ;CopySelectedTextToClipboard()
   Run, %Browser% %clipboard%
return

; Context specific hotkeys for Gmail Tasks
#IfWinActive Tasks ; assumes SetTitleMatchMode = 2
; Window position assumes Chrome and may break if browser or app changes
^tab::
   WinGetPos, ,,tasksWinWidth,tasksWinHeight
   clickPosX := (tasksWinWidth - 27)
   clickPosY := (tasksWinHeight - 22) ; 42 for Firefox
   Click %clickPosX%, %clickPosY%
return
#IfWinActive
; End of Gmail Tasks context


;
; Lotus Notes lameness mitigation
;
#IfWinActive ahk_class NOTES

; Refile message (mimic Outlook)
^+v:: Send, {ALTDOWN}7{ALTUP}m

; Refile message into 'Saved' folder (ala gmail "archive=y")
^+y::
   Send, {ALTDOWN}7{ALTUP}m
   WinWait, Move To Folder, 
   IfWinNotActive, Move To Folder, , WinActivate, Move To Folder, 
   WinWaitActive, Move To Folder, 
   Send, s{ENTER}
return

; Reply (mimic Outlook)
^r::Send, {ALTDOWN}2e{ALTUP}

; Forward (mimic Outlook)
;^f::Send, {ALTDOWN}4o{ALTUP}

; New email (mimic Outlook)
;^Enter::Send, {ALTDOWN}1{ALTUP}

; Send a message (mimic Outlook)
; disabled for now - made an oopsie send with this one...
;^Enter::Send, {ALTDOWN}1{ALTUP}

; Check spelling (Office hotkey)
F7::Send, {ALTDOWN}ek{ALTUP}

; Go to ... (mimic Outlook, note: brittle implementation via mouse clicks)
; Mail
^1::Send {Click, 16,  118}
; Calendar (with the addition of "Go to today")
^2::
   Send {Click, 16,  149}
   Send {Click, 84,  318}
return
; Contacts
^3::Send {Click, 16,  274}
; Inbox
^+i::
   Send {Click, 16,  118}
   Send {Click, 77,  178}
return

#IfWinActive
;
; End Lotus Notes
;

; Quicken "missing toolbar" bug workaround
;#IfWinActive ahk_class QFRAME
;^#q::
;   MouseClick, left,  58,  39
;   Sleep, 200
;   MouseClick, left,  88,  186
;   WinWait, Customize Toolbar, 
;   IfWinNotActive, Customize Toolbar, , WinActivate, Customize Toolbar, 
;   WinWaitActive, Customize Toolbar, 
;   Send, {ALTDOWN}io{ALTUP}
;return
;#IfWinActive


;^#1::
;   Run, %HOME%\lnk\ChromeIncognito.lnk  http://google.com
;return
;
